#include <iostream>
using namespace std;

struct res1 {
  int maxGrass;  // 最大吃草量
  int count;     // 草皮数量（路径 path 长度，用于最终结果 for 输出）
  int* path;     // 吃草路径
};

res1 resolve1(int grass[], int len) {
  res1 res;
  if (len < 1) {
    res = {0, 0, {0}};
  } else if (len == 1) {
    int path[1] = {1};
    res = {grass[0], 1, path};
  } else {
    res1 temp;
    // 吃第一块
    int pathE[len / 2] = {1};
    res1 eat = {grass[0], 1, pathE};
    temp = resolve1(&grass[2], len - 2);
    eat.maxGrass += temp.maxGrass;
    eat.count += temp.count;
    for (int i = 0; i < temp.count; i++) {
      eat.path[i + 1] = temp.path[i] + 2;
    }
    // 不吃第一块
    int pathN[len / 2] = {0};
    res1 neat = {0, 0, pathN};
    temp = resolve1(&grass[1], len - 1);
    neat.maxGrass += temp.maxGrass;
    neat.count += temp.count;
    for (int i = 0; i < temp.count; i++) {
      neat.path[i] = temp.path[i] + 1;
    }
    res = eat.maxGrass >= neat.maxGrass ? eat : neat;
  }
  return res;
}

int main() {
  // 输入测试数据
  int N, I;
  cin >> N >> I;
  int grass[N];
  for (int j = 0; j < N; j++) {
    cin >> grass[j];
  }
  int lenL = I - 2, lenR = N - I - 1;          // 左右数组长度
  int startL = I - 3, startR = I + 1;          // 左右数组起始位置
  int grassL[lenL] = {0}, grassR[lenR] = {0};  // 初始化左右数组
  // 填充左右数组
  for (int j = 0; j < lenL; j++) {
    grassL[j] = grass[startL - j];
  }
  for (int j = 0; j < lenR; j++) {
    grassR[j] = grass[startR + j];
  }

  // 向左吃
  res1 left = resolve1(grassL, lenL);
  // 向右吃
  res1 right = resolve1(grassR, lenR);
  // 记录结果
  int path[N / 2] = {I};
  res1 res = {grass[I - 1], 1, path};
  // 哪个方向吃得多选哪个方向，一样则向左
  if (left.maxGrass >= right.maxGrass) {
    res.count += left.count;
    res.maxGrass += left.maxGrass;
    for (int j = 0; j < left.count; j++) {
      res.path[j + 1] = I - 1 - left.path[j];
    }
  } else {
    res.count += right.count;
    res.maxGrass += right.maxGrass;
    for (int j = 0; j < right.count; j++) {
      res.path[j + 1] = I + 1 + right.path[j];
    }
  }
  // 输出结果
  cout << res.maxGrass << "\n";
  for (int j = 0; j < res.count - 1; j++) {
    cout << res.path[j] << " ";
  }
  cout << res.path[res.count - 1];
}